#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "../../src/module/amqp/amqp_comm9.h"
#include "../../src/module/amqp/amqp_core.h"
#include "../../src/module/amqp/config.h"
#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frbyte_buffer.h"
#include "frlist.h"
#include "frreport_comm.h"
#include "../comm/apmtest_comm.h"
#include "apmtest_cunit.h"


extern int __amqp_get_string_0_9_0(Frbyte_Packet *p_st_data, char **pp_out, int i_flag_need);

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


static void __case1(void)
{
    Frbyte_Packet *p_st_data = NULL;
    char *p_out = NULL;
    int i_flag_need = FR_YES;
    int i_ret = 0;

    p_st_data = bytebuff_creat ();

    bytebuff_add (p_st_data, (char *)"\x53\x00\x00\x00\x02\x65\x65", 7);

    i_ret = __amqp_get_string_0_9_0 (p_st_data, &p_out, i_flag_need);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_STRING_EQUAL(p_out, "ee");

    frfree (p_out);
    bytebuff_free (&p_st_data);

    return;

}

static void __case2(void)
{
    Frbyte_Packet *p_st_data = NULL;
    char *p_out = NULL;
    int i_flag_need = FR_NO;
    int i_ret = 0;

    p_st_data = bytebuff_creat ();

    bytebuff_add (p_st_data, (char *)"\x53\x00\x00\x00\x02\x65\x65", 7);

    i_ret = __amqp_get_string_0_9_0 (p_st_data, &p_out, i_flag_need);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_PTR_NULL(p_out);

    bytebuff_free (&p_st_data);

    return;

}

static void __case3(void)
{
    Frbyte_Packet *p_st_data = NULL;
    char *p_out = NULL;
    int i_flag_need = FR_NO;
    int i_ret = 0;

    i_ret = __amqp_get_string_0_9_0 (p_st_data, &p_out, i_flag_need);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    return;

}

int add_suite___amqp_get_string_0_9_0(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __amqp_get_string_0_9_0()", __suite_init, __suite_cleanup)) == NULL)
    return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);

    return FR_SUCC;

}

